﻿using SQLite;
using System.Collections.Generic;
using System.Linq;

namespace NewsReader.Helpers.Orm
{
    public sealed class NewsFormatter
    {
        private static IDictionary<string, NewsFormatter> s_configuredFormatters = FromConfig();
        
        private static IDictionary<string, NewsFormatter> FromConfig()
        {
            return PersistenceHelper.GetNewsFormatters().ToDictionary( nf => nf.Name);
        }
            
        public static NewsFormatter Named(string name)
        {
           return s_configuredFormatters[name]; 
        }

        public static IEnumerable<NewsFormatter> All
        {
            get { return s_configuredFormatters.Values; }
        }

        [Column("id"), PrimaryKey, AutoIncrement ]
        public int Id
        {
            get;
            set;
        }

        [Column("Name")]
        public string Name
        {
            get;
            set;
        }

        [Column("Uri")]
        public string Uri
        {
            get;
            set;
        }

        [Column("UserAgent")]
        public string UserAgent
        {
            get;
            set;
        }

        [Column("type_id")]
        public string TypeID
        {
            get;
            set;
        }

        [Column("requires_payment")]
        public bool IsPaymentRequired
        {
            get;
            set;
        }
    }
}
